/**
 * Copyright (c) 2010-2011 Pierre Labatut
 *
 * This file is part of Space-Chronicles project.
 *
 * Space-Chronicles is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/space-chronicles/>.
 */
package space.app.meshview.state;

import javax.media.opengl.GL3bc;
import jinngine.math.Matrix4;
import jinngine.math.Quaternion;
import jinngine.math.Vector3;
import space.model.Camera;
import space.model.MdlEmpty;

/**
 * This manipuilation algorythm is inspired from Blender
 * @author Pierre
 */
public class MeshCamera implements Camera {

   
    /**
     * Distance from the viewpoint to the origin
     */
    public double currentDistance = 500.;
    /**
     * Current resulting rotation from the trackball algorythm
     */
    final Quaternion viewquat = new Quaternion(0, 1, 0, 0);
    /**
     * Current resulting rotation from the trackball algorythm
     */
    final Vector3 center = new Vector3();    
    

    

    public MeshCamera() {
       
    }

    public Matrix4 viewpoint() {
        final Matrix4 viewpoint = new Matrix4();
        viewquat.toMatrix4(viewpoint);
        Matrix4.multiply(viewpoint, Matrix4.translation(center), viewpoint);
        viewpoint.a34 -= currentDistance;
        return viewpoint;
    }

    public void draw(GL3bc gl) {

        MdlEmpty.drawBasis(gl, (float) (currentDistance * .5f));
    }

    public double fovy() {
        return 90;
    }

    public double near() {
        return Math.min(10,currentDistance*.1);
    }

    public double far() {
        return 3000;
    }

   
}
